package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

import java.util.Iterator;
import java.util.Map;

public class InfoCMD extends Command {
    public InfoCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不能使用此命令");
        } else if (args.length != 1) {
            sender.sendMessage("§c参数错误");
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
        } else {
            Iterator var18 = Main.getInstance().getProxy().getPlayers().iterator();
            while (var18.hasNext()) {
                ProxiedPlayer player1 = (ProxiedPlayer) var18.next();
                if (player1.getName().equalsIgnoreCase(args[0])) {
                    sender.sendMessage("§a所在服务器: " + player1.getServer().getInfo().getName());
                    sender.sendMessage("§aIP: " + player1.getAddress().getAddress().getHostAddress());
                    sender.sendMessage("§aPing: " + player1.getPing());
                    Map<String, String> map = player1.getModList();
                    Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
                    StringBuilder sb = new StringBuilder("§aMods: ");
                    while (it.hasNext()) {
                        Map.Entry<String, String> entry = it.next();
                        sb.append(";" + entry.getKey() + "(" + entry.getValue() + ")");
                    }
                    sender.sendMessage(sb.toString());
                    sender.sendMessage("§a提示: /ban <ip>可以封禁ip!");
                    return;
                }
            }
            sender.sendMessage("§c查无此人!");
        }
    }
}
